package com.terry.test2.dp;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;

import javax.xml.bind.ValidationException;

/**
 * @author 小八
 * @date 2023年02月01日15:57
 */
public abstract class DpBase<T extends DpBase<?>> {

    protected void notNull(Object obj,String message) throws ValidationException {
        if(obj == null){
            throw new ValidationException(message);
        }
    }

    protected void notEmpty(Object obj,String message) throws ValidationException {
        if(ObjectUtil.isEmpty(obj)){
            throw new ValidationException(message);
        }
    }

    protected void isTrue(Boolean status,String message)throws ValidationException{
        if(!Boolean.TRUE.equals(status)){
            throw new ValidationException(message);
        }
    }
    protected void isFalse(boolean status,String message)throws ValidationException{
        if(Boolean.TRUE.equals(status)){
            throw new ValidationException(message);
        }
    }

    public String serialize(){
        return JSONUtil.toJsonStr(this);
    }

    public static <T> T deserialize(String jsonString, Class<T> beanClass) {
        return JSONUtil.toBean(jsonString,beanClass);
    }

}
